package com.qianchang.microfinance.view.mine.loan;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qianchang.microfinance.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 电脑 on 2018/1/16.
 */

public class HSWithdrawAdapter extends BaseAdapter{

    private Context context;
    private LayoutInflater inflater;
    private List<String> listStr = new ArrayList<>();
    private int index = -1;

    public HSWithdrawAdapter(Context mContext){
        this.context = mContext;
        inflater = LayoutInflater.from(context);

        String withone = mContext.getString(R.string.withdraw_one);
        String withone1 = mContext.getString(R.string.withdraw_one1);
        //String withtwo = mContext.getString(R.string.withdraw_two);
        //String withthree = mContext.getString(R.string.withdraw_three);
        //String withfour = mContext.getString(R.string.withdraw_four);
        listStr.add(withone);
        listStr.add(withone1);
        //listStr.add(withtwo);
        //listStr.add(withthree);
        //listStr.add(withfour);

    }

    public void setIndex(int mIndex){
        this.index = mIndex;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if(listStr != null && listStr.size() > 0){
            return listStr.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return listStr.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(int postion, View view, ViewGroup viewGroup) {

        Holder holder = null;
        if(view == null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_schedule_layout,null);
            holder.checkImg = (ImageView) view.findViewById(R.id.img_chek_id);
            holder.lineView = (LinearLayout)view.findViewById(R.id.view_line_id);
            holder.discsText = (TextView) view.findViewById(R.id.tv_description_id);
            view.setTag(holder);
        }else{
            holder = (Holder)view.getTag();
        }

        if(postion <= index){
            holder.checkImg.setImageResource(R.drawable.img_process_s);
            holder.lineView.setBackgroundResource(R.color.getCodeTextColor_blue);
            holder.lineView.setVisibility(View.VISIBLE);
            holder.discsText.setTextColor(R.color.getCodeTextColor_blue);
        }else{
            holder.checkImg.setImageResource(R.drawable.img_process_n);
            holder.lineView.setBackgroundResource(R.color.color_b8b8b8);
            holder.lineView.setVisibility(View.VISIBLE);
            holder.discsText.setTextColor(R.color.color_2c2c2c);
        }
        if(postion == listStr.size()-1){
            holder.lineView.setVisibility(View.GONE);
        }

        String str = listStr.get(postion);
        holder.discsText.setText(str);

        return view;
    }

    private class Holder{
        public ImageView checkImg;
        public LinearLayout lineView;
        public TextView discsText;
    }

}
